<?php
require_once 'BaseController.php';

/**
 * 【PC版】店舗詳細 コントローラ
 */
class Renew_ShopdetailController extends Renew_BaseController
{

    /**
     * メインアクション
     */
    public function indexAction()
    {
        $params = $this->getParameters();
        $code = $params['Code'];

        $this->makeTemplateParams($code);
        $this->displayBody2('index');
    }

    private function makeTemplateParams($code)
    {
        $model = new Shop_Model_Detail();
        $model_staff = new Renew_Model_TenpoStaff();
        $shop_tatemono = new Renew_Model_BukkenTenpo();
        $rstdtl_model = new Rstdtl_Model_Bukendtl();

        $params = array();
        $params['ShopCd'] = $code;

        $data = $model->getList($params);
        $data = $model->convertData($data);

        $apalogurl = $this->_config['apm']['apl']['apalog']['baseurl'];
        $tenpoimageurl = $this->_config['apm']['apl']['imagesvurl'] . 'fs/tenpoimg/';
        $data = $model->convertData($data[0], $apalogurl, $tenpoimageurl);
        $this->_data['shop'] = $data;

        $this->_data['tatemono'] = $shop_tatemono->getTatemonoListByTenpoCD($code);

        $staff_data = $model_staff->getStaffComment($code);
        $staff_data = $model_staff->convertStaffComment($staff_data);
        $this->_data['staff'] = $staff_data['STAFF'];

        $this->_data['RandomPrefs'] = $this->getRandomPrefs(5);
        $this->_data['seo_search_data']['KODAWARI'] = Apm_Seo::getSeoImpKodawari(0, 6);

        $this->getAreaData();

        // PV増分処理
        $rstdtl_model->S_RegPageViewLog($this->_data['shop']['M05_TENPO_CD'], 1, 0, "NULL", 1);
    }

    private function getAreaData()
    {
        $prefCd = $this->_data['shop']['M05_TENPO_TODOUFUKEN_CD'];
        $cityCd = $prefCd . $this->_data['shop']['M05_TENPO_SHIKUCHOUSON_CD'];

        $model = new Search_Model_Selareasearch();
        $this->_data['PrefInfo'] = $model->getSimpleArea($prefCd);

        $this->_data['PrefName'] = $this->getPrefName($prefCd);
        $this->_data['PrefNameJP'] = $this->getPrefNameJP($prefCd);
        $this->_data['PrefNameJPWithoutPostfix'] = $this->getPrefNameWithoutPostfix($this->_data["shop"]["M05_TENPO_TODOUFUKEN"]);

        $selcyoModel = new Search_Model_Selcyo(); // 市区町村
        $params = array();
        $params['PrefCd'] = array(
            $prefCd
        );
        $params['CityCd'] = array(
            $cityCd
        );
        $shiku = $selcyoModel->getShikucyosonNameByShikucyosonCd($params);
        $this->_data['ShikuName'] = $shiku[0]['M01_SHIKUCHOUSON_ALIAS'];
        $this->_data['ShikuCd'] = substr($cityCd, 3, 3);
    }

    /**
     * SEO対策用のmetaタグに配置する文章を設定
     */
    protected function setSeoMeta()
    {
        $params = $this->getParameters();
        $tenpoName = $this->_data['shop']['M05_TENPO_NAME'];

        $this->_meta_title = 'アパマンショップ' . $tenpoName . 'で賃貸物件を探す 【アパマンショップ】';
        $this->_meta_description = 'アパマンショップ' . $tenpoName . 'の店舗情報はこちら。アパマンショップネットワークで';
        $this->_meta_keywords = 'アパマンショップ' . $tenpoName . ',';
        $this->_alternate_url = 'sp/shop/' . $params['Code'] . '/';
    }

}
?>